package com.ruoyi.web.controller.ring;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ring.domain.UserPhysiology;
import com.ruoyi.ring.service.IUserPhysiologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生理期信息Controller
 * 
 * @author liuwp
 * @date 2025-09-30
 */
@RestController
@RequestMapping("/ring/user_physiology")
public class UserPhysiologyController extends BaseController
{
    @Autowired
    private IUserPhysiologyService userPhysiologyService;

    /**
     * 查询生理期信息列表
     */
    @PreAuthorize("@ss.hasPermi('ring:user_physiology:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPhysiology userPhysiology)
    {
        startPage();
        List<UserPhysiology> list = userPhysiologyService.selectUserPhysiologyList(userPhysiology);
        return getDataTable(list);
    }

    /**
     * 导出生理期信息列表
     */
    @PreAuthorize("@ss.hasPermi('ring:user_physiology:export')")
    @Log(title = "生理期信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPhysiology userPhysiology)
    {
        List<UserPhysiology> list = userPhysiologyService.selectUserPhysiologyList(userPhysiology);
        ExcelUtil<UserPhysiology> util = new ExcelUtil<UserPhysiology>(UserPhysiology.class);
        util.exportExcel(response, list, "生理期信息数据");
    }

    /**
     * 获取生理期信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:user_physiology:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userPhysiologyService.selectUserPhysiologyById(id));
    }

    /**
     * 新增生理期信息
     */
    @PreAuthorize("@ss.hasPermi('ring:user_physiology:add')")
    @Log(title = "生理期信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPhysiology userPhysiology)
    {
        return toAjax(userPhysiologyService.insertUserPhysiology(userPhysiology));
    }

    /**
     * 修改生理期信息
     */
    @PreAuthorize("@ss.hasPermi('ring:user_physiology:edit')")
    @Log(title = "生理期信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPhysiology userPhysiology)
    {
        return toAjax(userPhysiologyService.updateUserPhysiology(userPhysiology));
    }

    /**
     * 删除生理期信息
     */
    @PreAuthorize("@ss.hasPermi('ring:user_physiology:remove')")
    @Log(title = "生理期信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userPhysiologyService.deleteUserPhysiologyByIds(ids));
    }
}
